package com.uvt.agenda.iterator;

import com.uvt.agenda.Event;

import java.util.ArrayList;

/**
 * Created by Cristian Holdunu on 03/02/14.
 * 21:09
 * TODO: Add Observable interface to this buddy. Whena  new event is added/deleted notify the views to update what they display
 */
public class EventsContainer {
    private ArrayList<Event> events = new ArrayList<Event>();

    public EventsContainer() {
    }

    public EventsContainer(ArrayList<Event> events) {
        this.events = events;
    }

    public ArrayList<Event> asList(){
        return events;
    }

    public void setEvents(ArrayList<Event> events) {
        this.events = events;
    }

    private class EventsIterator implements EIterator {
        private int position = 0;

        @Override
        public boolean hasNext() {
            if (position < events.size())
                return true;
            return false;
        }

        @Override
        public Event next() {
            if (hasNext()) {
                return events.get(position++);
            }
            return null;
        }
    }

    public EventsIterator getIterator(){
        return new EventsIterator();
    }

    public int size(){
        return events.size();
    }

    public void addEvents(ArrayList<Event> newEvents){
        this.events.addAll(newEvents);
    }

    public void addEvents(EventsIterator eventsIterator){
        while (eventsIterator.hasNext()){
            this.events.add(eventsIterator.next());
        }
    }
    public void add(Event event){
        this.events.add(event);
    }

    public void removeEvent(Event event) {
        if (this.events.contains(event)){
            this.events.remove(event);
        }
    }
}
